package cn.oms.oms.controller;


import cn.oms.oms.entity.Admission;
import cn.oms.oms.service.IAdmissionService;
import cn.oms.oms.vo.AdmissionVo;
import cn.oms.oms.vo.AppointmentVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AllenChen曾晨
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/oms/admission")
@Slf4j
public class AdmissionController {

    @Autowired
    public IAdmissionService admissionService;

    /**
     * 根据查询条件查询入院记录列表
     * @param admissionVo
     * @return
     */
    @PostMapping("/selectAdmissionList")
    public PageInfo<Admission> selectAdmissionList(AdmissionVo admissionVo){

        if(admissionVo.getPageNum()==null||admissionVo.getPageNum()==0){
            admissionVo.setPageNum(1);
        }
        if(admissionVo.getPageSize()==null||admissionVo.getPageSize()==0){
            admissionVo.setPageSize(10);
        }
        log.debug("接收到信息:{}",admissionVo);
        PageInfo<Admission> pageInfo = admissionService.selectAdmissionList(admissionVo);
        return pageInfo;
    }


    /**
     * 根据入院号查详情
     * @param admissionVo
     * @return
     */
    @PostMapping("/selectAdmissionDetail")
    public Admission selectAdmissionDetail(AdmissionVo admissionVo){
        log.debug("接收到信息:{}",admissionVo);
        Admission admission = admissionService.selectAdmissionDetail(admissionVo);
        return admission;
    }

    /**
     * 新增入院登记
     * @param admissionVo
     * @return
     */
    @PostMapping("/addAdmission")
    public String addAdmission(AdmissionVo admissionVo){
        log.debug("接收到信息:{}",admissionVo);
        String res = admissionService.addAdmission(admissionVo);
        return res;
    }
    /**
     * 修改入院登记
     * @param admissionVo
     * @return
     */
    @PostMapping("/updateAdmission")
    public String updateAdmission(AdmissionVo admissionVo){
        log.debug("接收到信息:{}",admissionVo);
        String res = admissionService.updateAdmission(admissionVo);
        return res;
    }
    /**
     * 删除入院登记
     * @param id
     * @return
     */
    @GetMapping("/deleteAdmission/{id}")
    public String deleteAdmission(@PathVariable Integer id){
        log.debug("接收到信息:{}",id);
        String res = admissionService.deleteAdmission(id);
        return res;
    }
}
